package cn.lwq.oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lwq.help.ConfigRead;
import cn.lwq.help.MyConnection;

/**
 * @since 2017年7月17日
 * @author lwq 719812998@qq.com
 * @description
*/
public class OracleConnection implements MyConnection {
	
	public static Connection oracleConnection = null;
	private String oracleUrl;
	
	public static Map<String,List<String>> MAP_COLUMN_TYPE = null;
	
	public OracleConnection() throws Exception {
		if(oracleConnection == null) {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			ConfigRead config = new ConfigRead();
			oracleUrl = config.getDBUrl(ConfigRead.ORACLE);
			Connection connection = DriverManager.getConnection(oracleUrl, ConfigRead.DATABASE_USER, ConfigRead.DATABASE_PASSWORD);
			oracleConnection = connection;
		}
		if(MAP_COLUMN_TYPE == null) {
			MAP_COLUMN_TYPE = new HashMap<String, List<String>>();
			//@非空
			List<String> notnulls = new ArrayList<String>();
			notnulls.add("VARCHAR");
			notnulls.add("VARCHAR2");
			notnulls.add("NVARCHAR");
			notnulls.add("NVARCHAR2");
			notnulls.add("CHAR");
			notnulls.add("LONG");
			//
			notnulls.add("NUMERIC");
			notnulls.add("NUMBER");
			notnulls.add("DECIMAL");
			notnulls.add("INTEGER");
			notnulls.add("FLOAT");
			//
			notnulls.add("LONG");
			notnulls.add("RAW");
			notnulls.add("LONGRAW");
			notnulls.add("BLOB");
			notnulls.add("CLOB");
			notnulls.add("NCLOB");
			MAP_COLUMN_TYPE.put(ConfigRead.$NOT_NULL, notnulls);
			//@length
			List<String> lengths = new ArrayList<String>();
			lengths.add("CHAR");
			lengths.add("VARCHAR");
			lengths.add("VARCHAR2");
			lengths.add("NVARCHAR");
			lengths.add("NVARCHAR2");
			MAP_COLUMN_TYPE.put(ConfigRead.$LENGTH, lengths);
			//@max
			List<String> maxs = new ArrayList<String>();
			maxs.add("DECIMAL");
			maxs.add("NUMERIC");
			maxs.add("NUMBER");
			maxs.add("INTEGER");
			maxs.add("FLOAT");
			MAP_COLUMN_TYPE.put(ConfigRead.$MAX, maxs);
			//@日期型
			List<String> dates = new ArrayList<String>();
			dates.add("DATE");
			MAP_COLUMN_TYPE.put(ConfigRead.$DATE, dates);
		}
	}
	
	@Override
	public Connection getConnection() {
		return oracleConnection;
	}
	
}
